<?php 
class ContentController extends CommonController{
	
	
	public function index(){
		
//		p($_SESSION);
		//nav循环
		$nav=$this->nav();
		$this->assign('nav',$nav);
		
		//左侧导航循环
		$Father=$this->cate();
		$this->assign('cate',$Father);
		
		//面包屑方法************8
		$cid=Q("get.cid","","intval");
		
		$data=K('Category')->all();
		$fatherCate=$this->_getFatherCate($data, $cid);
		$fatherCate=array_reverse($fatherCate);
		$this->assign('fatherCate',$fatherCate);
		
		//导航最后的名字
		
		$gid=Q("get.gid",'','intval');
		$goods=K("Goods")->where("gid={$gid}")->find();
		$this->assign('goods',$goods);
//		p($goods);
		//规格
				
		$attr=M()->join("__goods_attr__ gt JOIN __shop_typeattr__ ta ON gt.shop_typeattr_taid=ta.taid")->where("goods_gid={$gid} and class=1")->group('taname')->all();
		
		foreach ($attr as $k => $v) {
			$attr[$k]['tem']=M('goods_attr')->where("shop_typeattr_taid={$v['shop_typeattr_taid']} and  goods_gid={$gid}")->all();
		}
		$this->assign("attr",$attr);
//		p($attr);
		        
       //类型属性表中找出网络制式的id
       
//     $taid=M("shop_typeattr")->where("taname = '网络制式'")->getField("taid");
//	   $net=M('goods_attr')->where("shop_typeattr_taid={$taid} and goods_gid={$gid}")->all();
//	   p($net);
//	   $this->assign('net',$net);
	   
	   
	   //类型属性表中找出颜色的id
	   
//	   $colortaid=M("shop_typeattr")->where("taname = '颜色'")->getField("taid");
//	   $color=M('goods_attr')->where("shop_typeattr_taid={$colortaid} and goods_gid={$gid}")->all();
//	   $this->assign('color',$color);
	   
	   //查询详情页
	   
	  $detail= K("Goodsdetail")->where("goods_gid={$gid}")->find();
	  $detail['photo']=explode(",", $detail['photo']);
	  foreach ($detail['photo'] as $k => $v) {
	  	$detail['sphoto'][]=dirname($v).'/small_'.basename($v);	
		$detail['mphoto'][]=dirname($v).'/mid_'.basename($v); 	   	
	  }
	  
	  
	  $this->assign('detail',$detail);
	   
//	   p($detail);


		
		
		$this->display();
	}


    public function ajaxmsg(){
    	$gid=Q("post.gid","","intval");
		$gtids=Q("post.gtid");
		$gtids=rtrim($gtids,",");
		$list=K("GoodsList")->where("goods_gid={$gid} and combin='{$gtids}'")->find();
		$glid = $list['glid'];
		
		if(!$list){
			$list['inventory']=0;
			$price=K("Goods")->where("gid={$gid}")->getField("price");
//			$number=K("Goods")->where("gid={$gid}")->getField("number");
			$list['price']=$price;
			$list['number']="";
		}else{
			$list['combin']=explode(",", $list['combin']);
			foreach ($list['combin'] as $k => $v) {
			
			$list['added'][]= K("Goodsattr")->where("gtid={$v} and goods_gid={$gid}")->getField("added");
			
				
			}
			$list['price']=0;
			foreach ($list['added'] as $k => $v) {
				$list['price']+=$v;
				
			}
			
			$price=K("Goods")->where("gid={$gid}")->getField("price");
			$list['price']=$list['price']+$price;
			$list['glid']=$glid;

			
		}
//		p($list);die;
		
		echo json_encode($list);die();
	
    }




    
	
	
}




 ?>